package com.zhongjh.app.util

import android.app.Activity
import com.zhongjh.albumcamerarecorder.album.filter.BaseFilter
import com.zhongjh.albumcamerarecorder.listener.OnResultCallbackListener
import com.zhongjh.albumcamerarecorder.settings.AlbumSetting
import com.zhongjh.albumcamerarecorder.settings.CameraSetting
import com.zhongjh.albumcamerarecorder.settings.MultiMediaSetting.Companion.from
import com.zhongjh.app.configuration.GifSizeFilter
import com.zhongjh.app.configuration.Glide4Engine
import com.zhongjh.common.entity.SaveStrategy
import com.zhongjh.common.enums.MimeType


/**
 * 拍照相册的便捷开发工具
 * @author zhongjh
 * @date 2022/7/7
 */
object AlbumCameraRecorderUtil {

    fun openImage(activity: Activity, listener: OnResultCallbackListener) {
        // 拍摄有关设置
        val cameraSetting = CameraSetting()
        // 支持的类型：图片，视频
        cameraSetting.mimeTypeSet(MimeType.ofImage())
        // 相册
        val albumSetting = AlbumSetting(false)
            // 是否显示多选图片的数字
            .countable(true)
            // 自定义过滤器
            .addFilter(GifSizeFilter(320, 320, 5 * BaseFilter.K * BaseFilter.K))
            // 开启原图
            .originalEnable(true)
            // 最大原图size,仅当originalEnable为true的时候才有效
            .maxOriginalSize(10)

        // 全局
        val globalSetting = from(activity).choose(MimeType.ofImage())
        // 开启相册功能
        globalSetting.albumSetting(albumSetting)
        // 开启拍摄功能
        globalSetting.cameraSetting(cameraSetting)

        globalSetting
            // 设置路径和7.0保护路径等等
            .allStrategy(
                SaveStrategy(
                    true,
                    "com.zhongjh.cameraapp.fileprovider",
                    "MvvmIbatis"
                )
            )
            // for glide-V4
            .imageEngine(Glide4Engine()) // 最大5张图片、最大3个视频、最大1个音频
            .maxSelectablePerMediaType(
                1,
                1,
                0,
                0,
                0,
                0,
                0
            )
            .forResult(listener)
    }
}